package cn.smbms.dao.user;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.Test;

import cn.smbms.pojo.Provider;
import cn.smbms.pojo.User;
import cn.smbms.utils.MyBatisUtil;

public class UserMapperTest {
	private Logger logger = Logger.getLogger(UserMapperTest.class);

	@Test
	public void test() {
		String resource = "mybatis-config.xml";
		int count = 0;
		SqlSession sqlSession = null;

		try {
			sqlSession = MyBatisUtil.createSqlSession();
			// InputStream is = Resources.getResourceAsStream(resource);
			// SqlSessionFactory factory = new SqlSessionFactoryBuilder()
			// .build(is);
			// sqlSession = factory.openSession();
			count = sqlSession.selectOne("cn.smbms.dao.user.UserMapper.count");
			logger.debug("总数是" + count);
			System.out.println(count);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			MyBatisUtil.closeSqlSession(sqlSession);
		}

	}

	//
	@Test
	public List<User> testGetUserList() {
		String resource = "mybatis-config.xml";
		List<User> userList = null;
		SqlSession sqlSession = null;

		try {
			sqlSession = MyBatisUtil.createSqlSession();
			// InputStream is = Resources.getResourceAsStream(resource);
			// SqlSessionFactory factory = new SqlSessionFactoryBuilder()
			// .build(is);
			// sqlSession = factory.openSession();
			// userList = sqlSession
			// .selectList("cn.smbms.dao.user.UserMapper.getUserList");
			userList = sqlSession.getMapper(UserMapper.class).getUserList();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			MyBatisUtil.closeSqlSession(sqlSession);
		}
		/*
		 * for (User u : userList) { // logger.debug("testGetUserList usercode "
		 * + u.getUserCode() // + " username " + u.getUserName());
		 * 
		 * // 筛选全部有日期格式错误 System.out.println("testGetUserList usercode " +
		 * u.getUserCode() + "  &  userPassword " + u.getUserPassword() +
		 * "  &  username " + u.getUserName()); }
		 */

		return userList;
	}// testGetUserList

	// testGetProviderList
	@Test
	public List<Provider> testGetProviderList() {
		String resource = "mybatis-config.xml";
		List<Provider> userList = null;
		SqlSession sqlSession = null;

		try {
			sqlSession = MyBatisUtil.createSqlSession();

			userList = sqlSession.getMapper(UserMapper.class).getProviderList();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			MyBatisUtil.closeSqlSession(sqlSession);
		}
		/*
		 * for (User u : userList) { // logger.debug("testGetUserList usercode "
		 * + u.getUserCode() // + " username " + u.getUserName());
		 * 
		 * // 筛选全部有日期格式错误 System.out.println("testGetUserList usercode " +
		 * u.getUserCode() + "  &  userPassword " + u.getUserPassword() +
		 * "  &  username " + u.getUserName()); }
		 */

		return userList;
	}// testGetProviderList
}
